package com.yiren.dbaa.view.button;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.RadioButton;

import com.yiren.dbaa.R;

/**
 * Created by WANGRONGXIANG
 * on 2021/5/8
 * Describe
 */
public class BottomLineRadioButton extends RadioButton {

    private Paint paint;

    public BottomLineRadioButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    private void initPaint() {
        paint = new Paint();
        paint.setColor(getResources().getColor(R.color.main_blue));
        paint.setAntiAlias(false);
        paint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas = drawBottomLine(canvas);
        super.onDraw(canvas);
    }

    private Canvas drawBottomLine(Canvas canvas) {
        int width = getWidth();
        int measuredHeight = getMeasuredHeight();
        if (isChecked()) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                canvas.drawRoundRect(width / 2 - 30, measuredHeight - 6, width / 2 + 30, measuredHeight, 3, 3, paint);
            } else {
                canvas.drawRect(width / 2 - 30, measuredHeight - 6, width / 2 + 30, measuredHeight, paint);
            }
        }
        return canvas;
    }
}